package com.anlu.thread.t5;

public class Singleton2 {
    private Singleton2(){}

//    private static volatile Singleton2 instance;

    private static volatile Singleton2 instance;



    public static Singleton2 getInstance(){
        if(instance==null){
            synchronized (Singleton2.class){
                if(instance==null){
                    instance = new Singleton2();//指令重排序
                    // 申请一块内存空间   // 1
                    // 在这块空间里实例化对象  // 2
                    // instance的引用指向这块空间地址   // 3

                }
            }
        }
        return instance;
    }

    public static Singleton2 getNewInstance(){
        if(instance==null){
            instance=new Singleton2();
        }
        return instance;
    }

}
